﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VisionRoc.Core;

namespace VisionRoc_Measure
{
    public partial class FormNanoSerialOverTcp : Form
    {
        NanoSerialOverTcp m_NanoSerialOverTcp;
        public FormNanoSerialOverTcp(NanoSerialOverTcp _NanoSerialOverTcp)
        {
            InitializeComponent();
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景 
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            m_NanoSerialOverTcp = _NanoSerialOverTcp;
        }

        private void FormNanoSerialOverTcp_Load(object sender, EventArgs e)
        {
            m_NanoSerialOverTcp.ReadParameter();
            txt_IP.Text = m_NanoSerialOverTcp.IP;
            txt_port.Text = m_NanoSerialOverTcp.Port.ToString();
        }

        private void btn_Set_Click(object sender, EventArgs e)
        {
            try
            {
                m_NanoSerialOverTcp.IP = txt_IP.Text;
                m_NanoSerialOverTcp.Port = Convert.ToInt32(txt_port.Text);
                m_NanoSerialOverTcp.WriteParameter();
                MessageBox.Show("保存设置成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存设置失败" + ex.ToString());
            }
        }
    }
}
